<?php

namespace App\Validator;

class AdminValidator extends Validator
{

    public function __construct()
    {
        parent::__construct();
    }

    public function validatorAdd($params)
    {
        if(count($params) <= 0) {
            return false;
        }

        $fields = [
            'username',
            'password',
            'repassword',
            'mobile'
        ];

        foreach($fields as $field) {
            if(false == in_array($field, array_keys($params))) {
                return false;
            }
        }

        if($params['password'] != $params['repassword']) {
            return false;
        }

        $vaildator = preg_match('#^13[\d]{9}$|^14[5,7,9]{1}\d{8}$|^15[0,1,2,3,5,6,7,8,9]{1}\d{8}$|^17[0,1,3,5,6,7,8]{1}\d{8}$|^18[\d]{9}$#',
            $params['mobile']);

        if(false == $vaildator) {
            return false;
        }

        return true;
    }

}
